package com.markbuikema.juliana32.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
import com.markbuikema.juliana32.R;
import com.markbuikema.juliana32.model.teams.Table;
import com.markbuikema.juliana32.model.teams.TableRow;

public class TableFragment extends Fragment {

	private Table table;
	private TableLayout layout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		table = (Table) getArguments().getSerializable("table");

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		View view = inflater.inflate(R.layout.view_table, container, false);
		layout = (TableLayout) view.findViewById(R.id.team_ranking_table);

		for (TableRow row : table.getRows()) {
			ViewGroup rowView = (ViewGroup) inflater.inflate(R.layout.list_table_row, layout, false);

			ImageView img = (ImageView) rowView.findViewById(R.id.table_row_image);
			TextView position = (TextView) rowView.findViewById(R.id.table_row_position);
			TextView teamName = (TextView) rowView.findViewById(R.id.table_row_name);
			TextView played = (TextView) rowView.findViewById(R.id.table_row_played);
			TextView points = (TextView) rowView.findViewById(R.id.table_row_points);
			
			
			UrlImageViewHelper.setUrlDrawable(img, row.getImgUrl());
			position.setText(row.getPosition());
			teamName.setText(row.getTeamName());
			played.setText(row.getPlayed());
			points.setText(row.getPoints());

			layout.addView(rowView);
		}

		return view;

	}
}
